package com.study.basercvadapter;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.study.basercvadapter.adapter.RcvAdapter;
import com.study.basercvadapter.base.BaseRcvAdapter;
import com.study.basercvadapter.databinding.ActivityMainBinding;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements BaseRcvAdapter.OnRecyclerViewItemClickListener<String> {

    private ActivityMainBinding viewBinding;
    List<String> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewBinding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(viewBinding.getRoot());
        initData();
        initView();
    }

    private void initData() {
        data = new ArrayList<>(1000);
        for (int i = 0; i < 1000; i++) {
            data.add("data:" + i);
        }
    }

    private void initView() {
        viewBinding.rcvMain.setLayoutManager(new LinearLayoutManager(this));
        RcvAdapter adapter = new RcvAdapter(data);
        viewBinding.rcvMain.setAdapter(adapter);

        adapter.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(@NonNull View v, int viewType, @NonNull String data, int position) {
        Toast.makeText(this, data, Toast.LENGTH_LONG).show();
    }
}